﻿@model MvcCmsOptIn.Models.OptInModel
@section HtmlHead{
    <link href="@Url.Content("/RazorThemes/" + Model._Portal.SkinName + "/css/optin.css")" rel="stylesheet" type="text/css" />
}
<div class="contentpage-outerdiv">
    <div id="container">
        <div class="breadcrumb">
            <span><a href="/optin-manager">Main Menu</a></span><span>» </span><span><a href="/optin-manager/subscribers">
                Subscribers</a></span><span>» </span><span>Import</span>
        </div>
        <div class="optin-content">
            <h1>
                Import Subscribers From Comma Seperated List</h1>
            <div>
                By clicking the link below all users from the comma seperated list will be added.  Dupes will be omitted.
                <div>
                    If email already exists in system do not add to the selected lists <input type="checkbox" id="doNotAddExisting" name="doNotAddExisting" />
                </div>
                <div class="importer-container">
                    <div>
                        <textarea id="emailList" class="import_csv"></textarea>
                    </div>
                    <div>
                        List(s) To Add Imported Users To:
                        @foreach (var list in Model._Lists)
                        {
                            <div>@Html.CheckBox(list.ListName, false, new {listId=list.ListID}) @list.ListName</div>
                        }
                    </div>
                    <div style="float:left; width:260px;">
                        <a href="javascript:void(0);" onclick="ImportSiteUsers();">
                            <img alt="batch import" border="0" src="/areas/mvccmsoptin/content/buttons/batch.gif" />
                        </a>      Click Icon To Begin Import
                    </div>
                    <div style="float:left; width:80px;">
                        <img border="0" id="busy" style="display:none;" src="/content/images/busy.gif" />
                        <span id="result"></span>
                    </div>
                    <div style="clear:both;"></div>
                </div>
            </div>
        </div>
    </div>
</div>
@section ScriptContent{
<script id="General" type="text/javascript">
    function ImportSiteUsers() {
        $("#busy").show();
        var doNotAddExisting = $("#doNotAddExisting").is(':checked');
        var listIds = new Array()
        jQuery("input:checkbox:checked").each(function () {
            var listId = $(this).attr("listId");
            if (listId) {
                listIds.push(listId);
            }
        });
        jQuery.ajaxSettings.traditional = true;
        $.post("/optinajax/importsubscribersfromcsv",
        {
            Emails: $("#emailList").val(),
            ListIds: listIds,
            DoNotAddExisting: doNotAddExisting
        },
      function (data) {
          var objdata = data;
          if (objdata.error) {
              //alert(objdata.error);
          }
          else {
              $("#result").text(objdata.result);
              $("#busy").hide();
          }
      }, "json");
    }

    $(document).ready(function () {

    });
</script>
}
@section SideBar{
}


